/*
 *  MutationOperator.cpp
 *  Genetski
 *
 *  Created by Srđan Rašić on 11/19/11.
 *
 */

#include "MutationOperator.h"
#include <cstdlib>

ProbabilityMutationOperator::ProbabilityMutationOperator(double bitMutationProbability) {
	_bitMutationProbability = bitMutationProbability;
}

void ProbabilityMutationOperator::Mutate(Chromosome& chm) {
	for (int i = 0; i < chm.size(); i++) {
		double r = rand() / (double)RAND_MAX;
		
		if (r <= _bitMutationProbability)
			chm[i] = (chm[i] == '0') ? '1' : '0';	// invert bit
	}
}